package org.musicguardian.core.scan;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.musicguardian.core.model.Library;
import org.musicguardian.core.scan.Scanner.ScannerListener;

public abstract class Scanner<T> {

	public interface ScannerListener {
		public void fileScanned(Object scannedObject );
	}

	protected List<ScannerListener> scannerListerners = new ArrayList<ScannerListener>();

	public void addScannerListener(ScannerListener scannerListener) {
		scannerListerners.add(scannerListener);
	}
	public abstract int getTotalWork();

	public abstract T run() throws Exception;

	protected void notifyScannerListeners(Object scannedObject) {
		for (Iterator<ScannerListener> iter = scannerListerners.iterator(); iter
				.hasNext();) {
			ScannerListener listener = iter.next();
			listener.fileScanned(scannedObject);
		}
	}

}
